﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class Map : MonoBehaviour
{
    public  int id;
    public int[,] map = null;

    public GameObject hallPanel;
    public Button chooseBtn;
    /// <summary>
    /// 图片
    /// </summary>
    private Image image;
    /// <summary>
    /// 锁
    /// </summary>
    public  Transform _lock;
    private void Awake()
    {
        chooseBtn = this.GetComponent<Button>();
        hallPanel = GameObject.Find("HallPanel");
        image = GameObject.Find("bg/Image").GetComponent<Image>();
        chooseBtn.onClick.AddListener(OnClickChooseBtn);
        //_lock = GameObject.Find("lock").transform;
        _lock.gameObject.SetActive(false);
    }

    void OnClickChooseBtn()
    {
        ///广告
        if (ReadData.instance.UnlockOrNot.ContainsKey(id))
        {
            if (ReadData.instance.UnlockOrNot[id] == 0)
            {
                AdManager.Instance.ShowVideo(() => {
                    ReadData.instance.SetUnlockOrNot(id);
                    _lock.gameObject.SetActive(false);
                });
                return;
            }
        }
        MapData mapData = ReadData.instance.GetMapById(id);

        AudioManager.Instance.Play("点击进入关卡声音");
        GameInit.instance.SetMap(mapData);

        hallPanel.SetActive(false);
    }
 

    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="id"></param>
    public void SetInfo(int id)
    {
        this.id = id;
        if(ReadData.instance.UnlockOrNot.ContainsKey(id))
        {
            if(ReadData.instance.UnlockOrNot[id]==0)
            {
                _lock.gameObject.SetActive(true);
            }
        }

    }
    /// <summary>
    /// 图标变为灰色
    /// </summary>
    public void pass_through()
    {
        image.color = new Color(0.5f, 0.5f, 0.5f);
    }


    // Update is called once per frame
    void Update()
    {
        
    }
}
